#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    vector<int> y(n);

    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        cin >> y[i];
    }
    vector<vector<int>> dp(k + 1, vector<int>(n + 1));
    for (int i = 1; i <= k; ++i) {
        for (int j = 1; j <= n; ++j) {
            dp[i][j] = dp[i][j - 1];
            if (i - x[j - 1]   >= 0)
                dp[i][j] = max(dp[i][j], dp[i - x[j - 1]][j - 1] + y[j -  1]);
        }
    }
    cout << dp.back().back() << endl;
    return 0;
}